﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections;

namespace QzEbook.View
{
    public class QzSiteMap:AbstractNode
    {
        private StringBuilder sb;
        private INode node = null;
        private INode current = null;

        public QzSiteMap()
        {
            sb = new StringBuilder();
        }

        public override void addChild(INode node)
        {
             if (this.node == null)
            {
                this.current = this.node = node;
                return;
            }
            INode child = node;
            (this.current as QzSiteMapNode).ChildNode = child;

            this.current = child;
        }
        public void addChild(string path, string title, string discript)
        {
            addChild(new QzSiteMapNode(path, title, discript));
        }

        public override string ToString()
        {
            if (node == null) return string.Empty;
            return string.Format("<div id='sitemap'>你现在的位置: {0}</div>", node.ToString());
        }
    }


    public class QzSiteMapNode:AbstractNode
    {
        private string path;
        private string title;
        private string discript;
        private string PathSeparatorTemplate = " » ";

        private INode childNode = null;

        public INode ChildNode
        {
            get { return childNode; }
            set { childNode = value; }
        }

        public QzSiteMapNode(string path, string title, string discript)
        {
            this.path = path;
            this.title = title;
            this.discript = discript;
        }


        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (this.ChildNode == null)
            {
                sb.AppendFormat("<span title='{0}'>{1}</span>", discript, title);
                return sb.ToString();
            }

            sb.AppendFormat("<a href='{0}' title='{1}'>{2}</a>", path, discript, title);
            sb.AppendFormat("{0}{1}", PathSeparatorTemplate, ChildNode.ToString());
            return sb.ToString();
        }

        public override void addChild(INode node)
        {
            throw new NotImplementedException();
        }
    }
}